package cn.shyouchi.wuguanjia.android.ui.event.labor;

import android.os.Parcel;
import android.os.Parcelable;

import com.chad.library.adapter.base.entity.AbstractExpandableItem;
import com.chad.library.adapter.base.entity.MultiItemEntity;

import java.util.List;

import cn.shyouchi.wuguanjia.android.utils.LogUtil;

/**
 * Created by Eenie on 2016/11/3 at 9:42
 * Email: 472279981@qq.com
 * Des:
 */

public class PersonEntity extends AbstractExpandableItem<PersonLaborEntity> implements MultiItemEntity, Parcelable {

    private int id;
    private String name;
    private String username;
//    private List<PersonLaborEntity> mLaborEntities = new ArrayList<>();

    private int days = 0;


    public PersonEntity() {

    }

    public PersonEntity(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public int getItemType() {
        return PersonLaborAdapter.ITEM_TYPE_PERSON_LABOR;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

//    public List<PersonLaborEntity> getLaborEntities() {
//        return mLaborEntities;
//    }
//
//    public void setLaborEntities(List<PersonLaborEntity> laborEntities) {
//        mLaborEntities = laborEntities;
//    }
//
//    public void addLabor(PersonLaborEntity personLaborEntity) {
//        mLaborEntities.add(personLaborEntity);
//    }


    public int getDays() {
        return days;
    }

    public void setDays(int days) {


        this.days = days;
    }

    /**
     * 判断当前个人工时是否超过考勤天数
     * @return
     */
    public boolean isCanAdd() {

        LogUtil.e("个人工时" + getPersonLaborCount());
        LogUtil.e("考勤工时" + getDays());


        return getPersonLaborCount() < getDays();
    }

    public int getPersonLaborCount() {
        List<PersonLaborEntity> entities = this.getSubItems();
        int c = 0;
        if (entities != null) {
            for (PersonLaborEntity e : entities) {
                c = c + e.getCount();
            }
        }
        return c;
    }


    @Override
    public int getLevel() {
        return 0;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.id);
        dest.writeString(this.name);
        dest.writeString(this.username);
        dest.writeInt(this.days);
    }

    protected PersonEntity(Parcel in) {
        this.id = in.readInt();
        this.name = in.readString();
        this.username = in.readString();
        this.days = in.readInt();
    }

    public static final Parcelable.Creator<PersonEntity> CREATOR = new Parcelable.Creator<PersonEntity>() {
        @Override
        public PersonEntity createFromParcel(Parcel source) {
            return new PersonEntity(source);
        }

        @Override
        public PersonEntity[] newArray(int size) {
            return new PersonEntity[size];
        }
    };
}
